<?php
class Front_Model_NewsCommentaires extends Jnd_Model_Abstract {
	
	protected $id = 0;
	protected $idNews = 0;
	protected $contenu = "";
	protected $creationDate;
	protected $creationUtilisateur;
	protected $modificationUtilisateur;
	protected $modificationDate;
	
	protected $_newsCoupee = false;
	
	/**
	 *
	 * @see Jnd_Model_Abstract::getId()
	 */
	public function getId() {
		return $this->id;
	}
	
	/**
	 *
	 * @see Jnd_Model_Abstract::setId()
	 */
	public function setId($id) {
		$this->id = $id;
	}
	
	public function getContenuLimite( $limite = null) {
	    if ( is_null($limite) ) {
	        $limiteChamp = Osml_Global_Constantes::OSML_CONFIG_HOME_NEWS_LONGUEUR;
	        $longueurMaxNews = Back_Model_Config::recuperationValeurParCle($limiteChamp, "valeur");
	        
	        $contenu = $this->getContenu();
	        if (strlen($contenu) > $longueurMaxNews) {
	            //    Il faut couper la news
	            $contenuLimite = substr($contenu, 0, $longueurMaxNews);
	            $this->_newsCoupee = true;
	            return $contenuLimite;
	        } else {
	            return $contenu;
	        }
	    }
	    
	}
	
	public function getLienNewsTexte() {
	     if ($this->_newsCoupee) {
	         return __("Lire la suite");
	     } else {
	         return __("Ouvrir la news");
	     }
	}
	
	/**
	 * Fonction permettant de renvoyer les commentaires d'uen news. 
	 * @param unknown_type $idNews
	 * @return multitype:Front_Model_NewsCommentaires
	 */
	public static function recupererCommentaires($idNews) {
	    $mapper = new Front_Model_Mapper_NewsCommentaires();
	    $datas = $mapper->recupererCommentaires($idNews);
	    $commentaires = array();
	    foreach( $datas as $data) {
	        $commentaires[] = new Front_Model_NewsCommentaires($data);
	    }
	    return $commentaires;
	}
}
